package com.hctg.forced2sleep.adapter;

import android.view.View;

import androidx.annotation.NonNull;

import com.actor.myandroidframework.utils.TextUtils2;
import com.actor.myandroidframework.utils.toaster.ToasterUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hctg.forced2sleep.R;

import java.text.SimpleDateFormat;

/**
 * description: 描述
 * company    :
 *
 * @author : ldf
 * date       : 2024/7/29 on 17
 * @version 1.0
 */
public class PageScanAdapter extends BaseQuickAdapter<Object, BaseViewHolder> {

    private boolean isShowCheckBox = false;
    private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

    public PageScanAdapter() {
        super(R.layout.item_page_scan);
        addChildClickViewIds(R.id.iv_check_box, R.id.tv_limit);
        setOnItemChildClickListener((adapter, view, position) -> {
            switch (view.getId()) {
                case R.id.iv_check_box:
                    //选中item
                    break;
                case R.id.tv_limit: //限制修改
                    ToasterUtils.warning("限制修改");
                    break;
                default:
                    break;
            }
        });
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, Object item) {
        // TODO: 2024/7/30 delete!
        int pos = holder.getAbsoluteAdapterPosition();
        holder.setGone(R.id.iv_check_box, !isShowCheckBox)
                .setImageResource(R.id.iv_icon, R.drawable.ic_launcher)
                .setText(R.id.tv_app_name, "app名称")
                .setText(R.id.tv_package_name, "com.android.settings")
                .setText(R.id.tv_limit, pos % 2 == 0 ? "限制修改" : TextUtils2.getStringFormat(" 在%s-%s可改 ", "22:22", "07:00"));
    }

    public void setIsShowCheckBox(boolean isShowCheckBox) {
        this.isShowCheckBox = isShowCheckBox;
        notifyDataSetChanged();
    }
}
